// file      : inverse/employee.hxx
// copyright : not copyrighted - public domain

#ifndef EMPLOYEE_HXX
#define EMPLOYEE_HXX

#include <vector>
#include <string>
#include <odb/core.hxx>

// Include TR1 <memory> header in a compiler-specific fashion. Fall back
// on the Boost implementation if the compiler does not support TR1.
//
#include <odb/tr1/memory.hxx>
#include <odb/tr1/lazy-ptr.hxx>

using std::tr1::shared_ptr;

using odb::tr1::lazy_shared_ptr;
using odb::tr1::lazy_weak_ptr;

// many-to-one  : employee <--> employer
class NoteTree;

class Note;

typedef std::vector<lazy_weak_ptr<Note> > Notes;

#pragma db object

class NoteTree {
public:
	NoteTree(const std::string& name)
			: name_(name) {}

	const std::string& name() const { return name_; }

	typedef ::Notes Note_Type;

	const Note_Type& notes() const { return notes_; }

	Note_Type& notes() { return notes_; }

private:
	friend class odb::access;

	NoteTree() {}

#pragma db id auto
	int id;
	std::string name_;

#pragma db value_not_null inverse(noteTree_)
	Note_Type notes_;//一对多
};


//多
#pragma db object

class Note {
public:
	typedef ::NoteTree NoteTree_Type;

	Note(const std::string& first, const std::string& last, lazy_shared_ptr<NoteTree_Type> noteTree)
			: first_(first),
			  noteTree_(noteTree) {}

	const std::string& first() const { return first_; }

	const lazy_shared_ptr<NoteTree_Type>& noteTree() const { return noteTree_; }

	void noteTree(lazy_shared_ptr<NoteTree_Type> noteTreeType) { noteTree_ = noteTreeType; }


private:
	friend class odb::access;

	Note() {}

#pragma db id auto
	unsigned long id_;

	std::string first_;

#pragma db not_null
	lazy_shared_ptr<NoteTree_Type> noteTree_;

};

#endif // EMPLOYEE_HXX
